package com.danco.planner.viewcontrollers;

import com.danco.planner.controllers.core.ViewController;
import com.danco.planner.supportclasses.enumeration.*;
import com.danco.planner.view.builders.AbstractViewsBuilder;
import com.danco.planner.view.builders.ConsoleViewsBuilder;
import com.danco.planner.view.core.AbstractButton;
import com.danco.planner.view.core.View;
import com.danco.planner.view.interfaces.IEventListener;

public class WelcomeVC extends ViewController implements IEventListener {

	public WelcomeVC() {
		this(new View());
	}

	public WelcomeVC(View view) {
		super(view);
		
		if (this.baseView != null) {
			
			
			AbstractViewsBuilder builder = new ConsoleViewsBuilder();
			baseView.addSubview(builder.buildLabel("Hello!"));
			baseView.addSubview(builder.buildLabel("Welcome to planner of courses!"));
			
			AbstractButton nextButton = builder.buildButton("Next button", "next", DefaultEventType.Next);
			AbstractButton closeButton = builder.buildButton("Close button", "close", DefaultEventType.Close);
			
			nextButton.addListener(this);
			closeButton.addListener(this);
			
			baseView.addSubviews(nextButton,closeButton);
		}
	}

	@Override
	public void handleAction(Object arg0, IEventType arg1) {
		
		if (arg1 == DefaultEventType.Next) {
			
			PlannerVC plannerVC = new PlannerVC(new View(), "Planner\n");
			pushViewController(plannerVC);
			
		} else
		if (arg1 == DefaultEventType.Close) {
			
			popViewController();
		}
	}

}
